package com.xtkj.accountjava.controller;


import com.xtkj.accountjava.base.Result;
import com.xtkj.accountjava.base.UnauthorizedException;
import com.xtkj.accountjava.entity.UserAccountEntity;
import com.xtkj.accountjava.entity.UserEntity;
import com.xtkj.accountjava.entity.VersionEntity;
import com.xtkj.accountjava.service.CommService;
import com.xtkj.accountjava.service.UserService;
import com.xtkj.accountjava.utils.RSAUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/app")
public class CommController {

    @Autowired
    CommService commService;

    @Autowired
    UserService userService;

    @GetMapping("/check_version")
    private Result checkVersion(
//            @RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String token
            @RequestParam Map<String,Object> requestMap
    ){
//        UserEntity userEntity = userService.checkToken(token);
//        if(userEntity==null){
//            throw  new UnauthorizedException("登录过期");
//        }
        String requestEntityData = (String) requestMap.get("data");
        HashMap<String,Object> parmsMap = RSAUtils.decryptStrToEntityData(requestEntityData, HashMap.class);
        String soft_from = (String) parmsMap.get("soft_from");
        if(soft_from==null)return  Result.error("查询失败");
        VersionEntity versionEntity = commService.checkVersion();
        if(versionEntity==null)return  Result.error("查询失败");
        return  Result.ok(versionEntity);
    }
}
